home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / Common / ZGeometry.h < prev    next >
Text File  |  1997-07-24  |  25KB  |  823 lines

  1. /*
  2.  *  File:       ZGeometry.h
  3.  *  Summary:    Point, size, and rectangle classes.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996-1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):
  10.  *
  11.  *         <7>     5/29/97    JDJ        Added TPoint and TLongPoint Distance friend functions.
  12.  *         <6>     5/17/97    JDJ        TPoint and TLongPoint operator <, <=, >, and >=
  13.  *                                    check v first. 
  14.  *         <5>     3/31/97    JDJ        Added SetWidth and SetHeight to rect classes. 
  15.  *         <4>     3/30/97    JDJ        Added <, <=, >, and >= operators to TPoint. 
  16.  *         <3>     3/26/97    JDJ        Added specializations of STL's copy, copy_backward, 
  17.  *                                    and uninitialized_copy functions.
  18.  *         <2>     3/11/97    JDJ        Made Pin methods const.
  19.  *         <1>     1/14/96    JDJ        Created.
  20.  */
  21.  
  22. #pragma once
  23.  
  24. #include <Fp.h>
  25.  
  26. #include <ZDebug.h>
  27. #include <ZTypes.h>
  28.  
  29.  
  30. //-----------------------------------
  31. //    Forward References
  32. //
  33. class TPoint;
  34. class TSize;
  35. class TRect;
  36.  
  37. class TLongPoint;
  38. class TLongSize;
  39. class TLongRect;
  40.  
  41.  
  42. // ===================================================================================
  43. //    class TPoint
  44. // ===================================================================================
  45. class TPoint {
  46.  
  47. //-----------------------------------
  48. //    Initialization/Destruction
  49. //
  50. public:
  51.                         TPoint()                                {}
  52.                         TPoint(short inX, short inY)            {h = inX; v = inY;}
  53.                         TPoint(const Point& rhs)                {h = rhs.h; v = rhs.v;}
  54.                         
  55. //-----------------------------------
  56. //    Conversion operators
  57. //
  58. public:
  59.                         operator Point() const                    {return *(const Point *) this;}
  60.                         operator Point*()                        {return (Point *) this;}
  61.  
  62. //-----------------------------------
  63. //    Arithmetic operators
  64. //
  65. public:
  66.             TPoint         operator-() const                        {return TPoint((short) (-h), (short) (-v));}
  67.     
  68.             TPoint         operator+(const TPoint& rhs) const        {return TPoint((short) (h + rhs.h), (short) (v + rhs.v));}
  69.             TPoint         operator+(const TSize& rhs) const;
  70.             TPoint         operator-(const TPoint& rhs) const        {return TPoint((short) (h - rhs.h), (short) (v - rhs.v));}
  71.             TPoint         operator-(const TSize& rhs) const;
  72.  
  73.             TPoint         operator*(short num) const                {return TPoint((short) (h*num), (short) (v*num));}
  74.     friend     TPoint         operator*(short num, const TPoint& rhs);
  75.             TPoint         operator/(short num) const                {ASSERT(num != 0); return TPoint((short) (h/num), (short) (v/num));}
  76.  
  77.             TPoint&     operator+=(const TPoint& rhs);    
  78.             TPoint&         operator+=(const TSize& rhs);    
  79.             TPoint&     operator-=(const TPoint& rhs);    
  80.             TPoint&     operator-=(const TSize& rhs);    
  81.                     
  82. //-----------------------------------
  83. //    Relational Operators
  84. //
  85. public:
  86.             bool         operator==(const TPoint& rhs) const        {return h == rhs.h && v == rhs.v;}
  87.             bool         operator!=(const TPoint& rhs) const        {return h != rhs.h || v != rhs.v;}
  88.  
  89.             bool         operator<(const TPoint& rhs) const        {return v < rhs.v || (v == rhs.v && h <  rhs.h);}
  90.             bool         operator<=(const TPoint& rhs) const        {return v < rhs.v || (v == rhs.v && h <= rhs.h);}
  91.  
  92.             bool         operator>(const TPoint& rhs) const        {return v > rhs.v || (v == rhs.v && h >  rhs.h);}
  93.             bool         operator>=(const TPoint& rhs) const        {return v > rhs.v || (v == rhs.v && h >= rhs.h);}
  94.  
  95. //-----------------------------------
  96. //    Misc
  97. //
  98. public:
  99.     friend    double         Distance(const TPoint& pt1, const TPoint& pt2)    {return sqrt((float) (pt1.h - pt2.h)*(pt1.h - pt2.h) + (float) (pt1.v - pt2.v)*(pt1.v - pt2.v));}
  100.  
  101. //-----------------------------------
  102. //    Member data
  103. //
  104. public:
  105.     short v;
  106.     short h;
  107. };
  108.  
  109.  
  110. // ===================================================================================
  111. //    class TSize
  112. // ===================================================================================
  113. class TSize {
  114.  
  115. //-----------------------------------
  116. //    Initialization/Destruction
  117. //
  118. public:
  119.                         TSize()                                    {}
  120.                         TSize(short inWidth, short inHeight)    {width = inWidth; height = inHeight;}
  121.  
  122. //-----------------------------------
  123. //    Conversion operators
  124. //
  125. public:
  126.                         operator Point() const                    {return *(const Point *) this;}
  127.                         operator Point*()                        {return (Point*) this;}
  128.  
  129. //-----------------------------------
  130. //    Arithmetic operators
  131. //
  132. public:
  133.             TSize         operator-() const                        {return TSize((short) (-width), (short) (-height));}
  134.     
  135.  
  136.             TSize         operator+(const TSize& rhs) const        {return TSize((short) (width + rhs.width), (short) (height + rhs.height));}
  137.             TSize         operator-(const TSize& rhs) const        {return TSize((short) (width - rhs.width), (short) (height - rhs.height));}    
  138.         
  139.             TSize         operator*(short num) const                {return TSize((short) (width*num), (short) (height*num));}
  140.     friend     TSize         operator*(short num, const TSize& rhs);
  141.             TSize         operator/(short num) const                {ASSERT(num != 0); return TSize((short) (width/num), (short) (height/num));}
  142.  
  143.             TSize&         operator+=(const TSize& rhs);            
  144.             TSize&         operator-=(const TSize& rhs);            
  145.         
  146. //-----------------------------------
  147. //    Relational Operators
  148. //
  149. public:
  150.             bool         operator==(const TSize& rhs) const        {return width == rhs.width && height == rhs.height;}
  151.             bool         operator!=(const TSize& rhs) const        {return width != rhs.width || height != rhs.height;}
  152.     
  153. //-----------------------------------
  154. //    Misc
  155. //
  156. public:
  157.             long         GetArea() const                            {return (long) width * height;}
  158.  
  159. //-----------------------------------
  160. //    Member data
  161. //
  162. public:
  163.     short height;
  164.     short width;
  165. };
  166.  
  167.  
  168. // ===================================================================================
  169. //    class TRect
  170. // ===================================================================================
  171. enum PointSelector {topLeft, botRight};
  172.  
  173. class TRect : public Rect {
  174.  
  175. //-----------------------------------
  176. //    Initialization/Destruction
  177. //
  178. public:
  179.                         TRect()                                    {}
  180.                         TRect(short inLeft, short inTop, short inRight, short inBottom)    {left = inLeft; top = inTop; right = inRight; bottom = inBottom;}
  181.  
  182.                         TRect(const TPoint& topLeftPt, const TPoint& botRightPt);
  183.                         TRect(const TPoint& topLeftPt, const TSize& size);
  184.                         TRect(const Rect& rect);
  185.  
  186. //-----------------------------------
  187. //    Conversion operators
  188. //
  189. public:
  190.                         operator const Rect*() const            {return (const Rect *) this;}
  191.                         operator Rect*()                        {return (Rect *) this;}
  192.  
  193. //-----------------------------------
  194. //     Dimensions
  195. //
  196. public:
  197.             short        GetWidth() const                        {return (short) (right - left);}
  198.             short         GetHeight() const                        {return (short) (bottom - top);}
  199.             TSize         GetSize() const                            {return TSize((short) (right - left), (short) (bottom - top));}
  200.             long         GetArea() const                            {return ((long) (right - left) * (bottom - top));}
  201.  
  202. //-----------------------------------
  203. //    Selectors
  204. //
  205. public:
  206.             TPoint&       operator[](PointSelector sel)            {return (sel == topLeft) ? (*((TPoint *)&top)) : (*((TPoint *)&bottom));}        
  207.             const TPoint& operator[](PointSelector sel) const    {return (sel == topLeft) ? (*((const TPoint *)&top)) : (*((const TPoint *)&bottom));}
  208.  
  209. //-----------------------------------
  210. //    Operations
  211. //
  212. public:
  213.             void         MoveTo(const TPoint& pt);
  214.             void         MoveBy(const TPoint& pt);
  215.             TRect         operator+(const TPoint& rhs) const        {return TRect((short) (left + rhs.h), (short) (top + rhs.v), (short) (right + rhs.h), (short) (bottom + rhs.v));}
  216.             TRect         operator+(const TSize& rhs) const        {return TRect((short) (left + rhs.width), (short) (top + rhs.height), (short) (right + rhs.width), (short) (bottom + rhs.height));}
  217.             TRect         operator-(const TPoint& rhs) const        {return TRect((short) (left - rhs.h), (short) (top - rhs.v), (short) (right - rhs.h), (short) (bottom - rhs.v));}
  218.             TRect         operator-(const TSize& rhs) const        {return TRect((short) (left - rhs.width), (short) (top - rhs.height), (short) (right - rhs.width), (short) (bottom - rhs.height));}
  219.                     
  220.             TRect         operator&(const TRect& rhs) const;
  221.             TRect         operator|(const TRect& rhs) const;
  222.         
  223.             TRect&         operator+=(const TPoint& rhs);
  224.             TRect&         operator+=(const TSize& rhs);
  225.             TRect&         operator-=(const TPoint& rhs);
  226.             TRect&         operator-=(const TSize& rhs);
  227.             
  228.             TRect&         operator&=(const TRect& rhs);    
  229.             TRect&         operator|=(const TRect& rhs);
  230.         
  231.             void         Inset(const TPoint& delta);
  232.             void         Inset(short dx, short dy);
  233.         
  234.             void         SetWidth(short size)                    {right = (short) (left + size);}
  235.             void         SetHeight(short size)                    {bottom = (short) (top + size);}
  236.             void         SetSize(const TSize& size)                {right = (short) (left + size.width); bottom = (short) (top + size.height);}
  237.             
  238. //-----------------------------------
  239. //    Relational Operators
  240. //
  241. public:
  242.             bool         operator==(const TRect& rhs) const        {return (left == rhs.left && right == rhs.right && top == rhs.top && bottom == rhs.bottom);}
  243.             bool         operator!=(const TRect& rhs) const        {return (!(*this == rhs));}
  244.  
  245. //-----------------------------------
  246. //    Misc
  247. //
  248. public:
  249.             bool         Contains(const TPoint& pt) const        {return (pt.v >= top && pt.v < bottom && pt.h >= left && pt.h < right);}
  250.                         // Returns true if pt is within the rectangle.
  251.         
  252.             bool         Contains(const TRect& rect) const        {return (rect.top >= top && rect.bottom <= bottom && rect.left >= left && rect.right <= right);}
  253.         
  254.             bool         Intersects(const TRect& rect) const        {return (left <= rect.right && right >= rect.left && top <= rect.bottom && bottom    >= rect.top);}
  255.                         // Return true if the rectangle intersects rect.
  256.         
  257.             bool         IsEmpty() const                            {return left >= right || top >= bottom;}
  258.                         // Returns true if width or height are zero.
  259.         
  260.             void         MakeEmpty()                                {left = right = top = bottom = 0;}
  261.                         // Empties the rectangle.
  262.         
  263.             void         CenterIn(const TRect& container);
  264.                         // Center the rectangle in the container.
  265.                 
  266.             void         MapTo(const TRect& container, double maxScaleFactor = 1.0);
  267.                         // Scales the rectangle so that it's within the container and
  268.                         // its size is as close as possible to the container's size. 
  269.                         // Note that this preserves the rectangle's aspect ratio and 
  270.                         // won't blow up the rectangle by an amount larger than 
  271.                         // maxScaleFactor.
  272.                 
  273.             TPoint         Pin(const TPoint& pt) const;
  274.                         // Returns the point within the rectangle closest to pt.
  275. };
  276.  
  277.  
  278. // ===================================================================================
  279. //    class TLongPoint
  280. // ===================================================================================
  281. class TLongPoint {
  282.  
  283. //-----------------------------------
  284. //    Initialization/Destruction
  285. //
  286. public:
  287.                         TLongPoint()                            {}
  288.                         TLongPoint(const TPoint& rhs)            {h = rhs.h; v = rhs.v;}
  289.                         TLongPoint(long inX, long inY)            {h = inX; v = inY;}
  290.                         
  291. //-----------------------------------
  292. //    Arithmetic operators
  293. //
  294. public:
  295.             TLongPoint     operator-() const                        {return TLongPoint(-h, -v);}
  296.     
  297.             TLongPoint     operator+(const TLongPoint& rhs) const    {return TLongPoint(h + rhs.h, v + rhs.v);}
  298.             TLongPoint     operator+(const TLongSize& rhs) const;
  299.             TLongPoint     operator-(const TLongPoint& rhs) const    {return TLongPoint(h - rhs.h, v - rhs.v);}
  300.             TLongPoint     operator-(const TLongSize& rhs) const;
  301.  
  302.             TLongPoint     operator*(long num) const                {return TLongPoint(h*num, v*num);}
  303.     friend     TLongPoint     operator*(long num, const TLongPoint& rhs);
  304.             TLongPoint     operator/(long num) const                {ASSERT(num != 0); return TLongPoint(h/num, v/num);}
  305.  
  306.             TLongPoint& operator+=(const TLongPoint& rhs);    
  307.             TLongPoint&    operator+=(const TLongSize& rhs);    
  308.             TLongPoint& operator-=(const TLongPoint& rhs);    
  309.             TLongPoint& operator-=(const TLongSize& rhs);    
  310.                     
  311. //-----------------------------------
  312. //    Relational Operators
  313. //
  314. public:
  315.             bool         operator==(const TLongPoint& rhs) const        {return (h == rhs.h && v == rhs.v);}
  316.             bool         operator!=(const TLongPoint& rhs) const        {return (h != rhs.h || v != rhs.v);}
  317.  
  318.  
  319.             bool         operator<(const TLongPoint& rhs) const        {return v < rhs.v || (v == rhs.v && h <  rhs.h);}
  320.             bool         operator<=(const TLongPoint& rhs) const        {return v < rhs.v || (v == rhs.v && h <= rhs.h);}
  321.  
  322.             bool         operator>(const TLongPoint& rhs) const        {return v > rhs.v || (v == rhs.v && h >  rhs.h);}
  323.             bool         operator>=(const TLongPoint& rhs) const        {return v > rhs.v || (v == rhs.v && h >= rhs.h);}
  324.  
  325. //-----------------------------------
  326. //    Misc
  327. //
  328. public:
  329.     friend    double         Distance(const TLongPoint& pt1, const TLongPoint& pt2)    {return sqrt((float) (pt1.h - pt2.h)*(pt1.h - pt2.h) + (float) (pt1.v - pt2.v)*(pt1.v - pt2.v));}
  330.  
  331. //-----------------------------------
  332. //    Member data
  333. //
  334. public:
  335.     long v;
  336.     long h;
  337. };
  338.  
  339.  
  340. // ===================================================================================
  341. //    class TLongSize
  342. // ===================================================================================
  343. class TLongSize {
  344.  
  345. //-----------------------------------
  346. //    Initialization/Destruction
  347. //
  348. public:
  349.                         TLongSize()                                {}
  350.                         TLongSize(const TSize& rhs)                {width = rhs.width; height = rhs.height;}
  351.                         TLongSize(long inWidth, long inHeight)    {width = inWidth; height = inHeight;}
  352.  
  353. //-----------------------------------
  354. //    Arithmetic operators
  355. //
  356. public:
  357.             TLongSize     operator-() const                        {return TLongSize(-width, -height);}
  358.     
  359.             TLongSize     operator+(const TLongSize& rhs) const    {return TLongSize(width + rhs.width, height + rhs.height);}
  360.             TLongSize     operator-(const TLongSize& rhs) const    {return TLongSize(width - rhs.width, height - rhs.height);}
  361.         
  362.             TLongSize     operator*(long num) const                {return TLongSize(width*num, height*num);}
  363.     friend     TLongSize     operator*(long num, const TLongSize& rhs);
  364.             TLongSize     operator/(long num) const                {ASSERT(num != 0); return TLongSize(width/num, height/num);}
  365.  
  366.             TLongSize&     operator+=(const TLongSize& rhs);            
  367.             TLongSize&     operator-=(const TLongSize& rhs);            
  368.         
  369. //-----------------------------------
  370. //    Relational Operators
  371. //
  372. public:
  373.             bool         operator==(const TLongSize& rhs) const    {return width == rhs.width && height == rhs.height;}    
  374.             bool         operator!=(const TLongSize& rhs) const    {return width != rhs.width || height != rhs.height;}
  375.     
  376. //-----------------------------------
  377. //    Misc
  378. //
  379. public:
  380.             long         GetArea() const                            {return width * height;}
  381.  
  382. //-----------------------------------
  383. //    Member data
  384. //
  385. public:
  386.     long height;
  387.     long width;
  388. };
  389.  
  390.  
  391. // ===================================================================================
  392. //    class TLongRect
  393. // ===================================================================================
  394. class TLongRect {
  395.  
  396. //-----------------------------------
  397. //    Initialization/Destruction
  398. //
  399. public:
  400.                         TLongRect()                                    {}
  401.                         TLongRect(long inLeft, long inTop, long inRight, long inBottom)    {left = inLeft; top    = inTop; right = inRight; bottom = inBottom;}
  402.                         TLongRect(const TLongPoint& topLeftPt, const TLongPoint& botRightPt);
  403.                         TLongRect(const TLongPoint& topLeftPt, const TLongSize& size);
  404.                         TLongRect(const TRect& rhs)                    {left = rhs.left; right = rhs.right; top = rhs.top; bottom = rhs.bottom;}
  405.  
  406. //-----------------------------------
  407. //     Dimensions
  408. //
  409. public:
  410.             long        GetWidth() const                            {return right - left;}
  411.             long         GetHeight() const                            {return bottom - top;}
  412.             TLongSize     GetSize() const                                {return TLongSize(right - left, bottom - top);}
  413.             long         GetArea() const                                {return (right - left)*(bottom - top);}
  414.  
  415. //-----------------------------------
  416. //    Selectors
  417. //
  418. public:
  419.             TLongPoint&       operator[](PointSelector sel)            {return (sel == topLeft) ? (*((TLongPoint *)&top)) : (*((TLongPoint *)&bottom));}            
  420.             const TLongPoint& operator[](PointSelector sel) const    {return (sel == topLeft) ? (*((const TLongPoint *)&top)) : (*((const TLongPoint *)&bottom));}
  421.  
  422. //-----------------------------------
  423. //    Operations
  424. //
  425. public:
  426.             void         MoveTo(const TLongPoint& pt);
  427.             void         MoveBy(const TLongPoint& pt);
  428.             
  429.             TLongRect     operator+(const TLongPoint& rhs) const        {return TLongRect(left + rhs.h, top + rhs.v, right + rhs.h, bottom + rhs.v);}
  430.             TLongRect     operator+(const TLongSize& rhs) const        {return TLongRect(left + rhs.width, top + rhs.height, right + rhs.width, bottom + rhs.height);}
  431.             TLongRect     operator-(const TLongPoint& rhs) const        {return TLongRect(left - rhs.h, top - rhs.v, right - rhs.h, bottom - rhs.v);}
  432.             TLongRect     operator-(const TLongSize& rhs) const        {return TLongRect(left - rhs.width, top - rhs.height, right - rhs.width, bottom - rhs.height);}
  433.                     
  434.             TLongRect     operator&(const TLongRect& rhs) const;
  435.             TLongRect     operator|(const TLongRect& rhs) const;
  436.         
  437.             TLongRect&     operator+=(const TLongPoint& rhs);
  438.             TLongRect&     operator+=(const TLongSize& rhs);
  439.             TLongRect&     operator-=(const TLongPoint& rhs);
  440.             TLongRect&     operator-=(const TLongSize& rhs);
  441.             
  442.             TLongRect&     operator&=(const TLongRect& rhs);    
  443.             TLongRect&     operator|=(const TLongRect& rhs);
  444.         
  445.             void         Inset(const TLongPoint& delta);
  446.             void         Inset(long dx, long dy);
  447.                 
  448.             void         SetWidth(long size)                            {right = left + size;}
  449.             void         SetHeight(long size)                        {bottom = top + size;}
  450.             void         SetSize(const TLongSize& size)                {right = left + size.width; bottom = top + size.height;}
  451.  
  452. //-----------------------------------
  453. //    Relational Operators
  454. //
  455. public:
  456.             bool         operator==(const TLongRect& rhs) const        {return (left == rhs.left && right == rhs.right && top == rhs.top && bottom == rhs.bottom);}
  457.             bool         operator!=(const TLongRect& rhs) const        {return (!(*this == rhs));}
  458.  
  459. //-----------------------------------
  460. //    Misc
  461. //
  462. public:
  463.             bool         Contains(const TLongPoint& pt) const        {return (pt.v >= top && pt.v < bottom && pt.h >= left && pt.h < right);}
  464.                         // Returns true if pt is within the rectangle.
  465.         
  466.             bool         Contains(const TLongRect& rect) const        {return (rect.top >= top && rect.bottom <= bottom && rect.left >= left && rect.right <= right);}
  467.         
  468.             bool         Intersects(const TLongRect& rect) const        {return (left <= rect.right && right >= rect.left && top <= rect.bottom && bottom    >= rect.top);}
  469.                         // Return true if the rectangle intersects rect.
  470.         
  471.             bool         IsEmpty() const                                {return left >= right || top >= bottom;}
  472.                         // Returns true if width or height are zero.
  473.         
  474.             void         MakeEmpty()                                    {left = right = top = bottom = 0;}
  475.                         // Empties the rectangle.
  476.         
  477.             void         CenterIn(const TLongRect& container);
  478.                         // Center the rectangle in the container.
  479.                 
  480.             void         MapTo(const TRect& container, double maxScaleFactor = 1.0);
  481.                         // Scales the rectangle so that it's within the container and
  482.                         // its size is as close as possible to the container's size. 
  483.                         // Note that this preserves the rectangle's aspect ratio and 
  484.                         // won't blow up the rectangle by an amount larger than 
  485.                         // maxScaleFactor.
  486.                 
  487.             TLongPoint     Pin(const TLongPoint& pt) const;
  488.                         // Returns the point within the rectangle closest to pt.
  489.  
  490. //-----------------------------------
  491. //    Member data
  492. //
  493. public:
  494.     long    top;
  495.     long    left;
  496.     long    bottom;
  497.     long    right;
  498. };
  499.  
  500.  
  501. //-----------------------------------
  502. //    Constants
  503. //
  504. extern const TPoint     kZeroPt;
  505. extern const TSize      kZeroSize;
  506. extern const TRect      kZeroRect;
  507.  
  508. extern const TLongPoint    kLongZeroPt;
  509. extern const TLongSize  kLongZeroSize;
  510. extern const TLongRect  kLongZeroRect;
  511.  
  512.  
  513. // ===================================================================================
  514. //    STL specializations
  515. // ===================================================================================
  516. DECLARE_STL_FUNCTIONS(TPoint);
  517. DECLARE_STL_FUNCTIONS(TSize);
  518. DECLARE_STL_FUNCTIONS(TRect);
  519. DECLARE_STL_FUNCTIONS(TLongPoint);
  520. DECLARE_STL_FUNCTIONS(TLongSize);
  521. DECLARE_STL_FUNCTIONS(TLongRect);
  522.  
  523.  
  524. // ===================================================================================
  525. //    Inlines
  526. // ===================================================================================
  527. inline TPoint TPoint::operator-(const TSize& rhs) const        
  528. {
  529.     return TPoint((short) (h - rhs.width), (short) (v - rhs.height));
  530. }
  531.  
  532. inline TPoint TPoint::operator+(const TSize& rhs) const        
  533. {
  534.     return TPoint((short) (h + rhs.width), (short) (v + rhs.height));
  535. }
  536.  
  537. inline TPoint& TPoint::operator+=(const TPoint& rhs)    
  538. {
  539.     h += rhs.h; 
  540.     v += rhs.v; 
  541.     
  542.     return *this;
  543. }
  544.  
  545. inline TPoint& TPoint::operator-=(const TPoint& rhs)    
  546. {
  547.     h -= rhs.h; 
  548.     v -= rhs.v; 
  549.     
  550.     return *this;
  551. }
  552.  
  553. inline TPoint& TPoint::operator+=(const TSize& rhs)
  554. {
  555.     h += rhs.width; 
  556.     v += rhs.height; 
  557.     
  558.     return *this;
  559. }
  560.     
  561. inline TPoint& TPoint::operator-=(const TSize& rhs)
  562. {
  563.     h -= rhs.width; 
  564.     v -= rhs.height; 
  565.     
  566.     return *this;
  567. }
  568.  
  569. #pragma mark -
  570.  
  571. inline TSize& TSize::operator+=(const TSize& rhs)        
  572. {
  573.     width     += rhs.width; 
  574.     height     += rhs.height; 
  575.     return *this;
  576. }
  577.  
  578. inline TSize& TSize::operator-=(const TSize& rhs)    
  579. {
  580.     width     -= rhs.width; 
  581.     height     -= rhs.height; 
  582.     return *this;
  583. }
  584.  
  585. #pragma mark -
  586.  
  587. inline TRect::TRect(const TPoint& topLeftPt, const TPoint& botRightPt)
  588. {
  589.     left    = topLeftPt.h;
  590.     top        = topLeftPt.v;
  591.     right    = botRightPt.h;
  592.     bottom    = botRightPt.v;
  593. }
  594.  
  595. inline TRect::TRect(const TPoint& topLeftPt, const TSize& size)
  596. {
  597.     left    = topLeftPt.h;
  598.     top        = topLeftPt.v;
  599.     right    = (short) (topLeftPt.h + size.width);
  600.     bottom    = (short) (topLeftPt.v + size.height);
  601. }
  602.  
  603. inline TRect::TRect(const Rect& rect)
  604. {
  605.     left    = rect.left;
  606.     top        = rect.top;
  607.     right    = rect.right;
  608.     bottom    = rect.bottom;
  609. }
  610.  
  611. inline void TRect::MoveBy(const TPoint& pt)
  612. {
  613.     left     += pt.h; 
  614.     top     += pt.v; 
  615.     right     += pt.h; 
  616.     bottom     += pt.v; 
  617. }
  618.  
  619. inline void TRect::MoveTo(const TPoint& pt)                
  620. {
  621.     this->MoveBy(TPoint((short) (pt.h - left), (short) (pt.v - top)));
  622. }
  623.  
  624. inline void TRect::Inset(short dx, short dy)
  625. {
  626.     top     += dy; 
  627.     left     += dx; 
  628.     bottom     -= dy; 
  629.     right     -= dx;
  630. }
  631.  
  632. inline void TRect::Inset(const TPoint& delta)                
  633. {
  634.     this->Inset(delta.h, delta.v);
  635. }
  636.  
  637. inline TRect& TRect::operator&=(const TRect& rhs)
  638. {
  639.     *this = *this & rhs; 
  640.     return *this;
  641. }
  642.     
  643. inline TRect& TRect::operator|=(const TRect& rhs)
  644. {
  645.     *this = *this | rhs; 
  646.     return *this;
  647. }
  648.  
  649. inline TRect& TRect::operator+=(const TPoint& rhs)
  650. {
  651.     this->MoveBy(rhs); 
  652.     return *this;
  653. }
  654.  
  655. inline TRect& TRect::operator-=(const TPoint& rhs)
  656. {
  657.     this->MoveBy(-rhs); 
  658.     return *this;
  659. }
  660.  
  661. inline TRect& TRect::operator+=(const TSize& rhs)
  662. {
  663.     this->MoveBy(TPoint(rhs.width, rhs.height)); 
  664.     return *this;
  665. }
  666.  
  667. inline TRect& TRect::operator-=(const TSize& rhs)
  668. {
  669.     this->MoveBy(TPoint((short) (-rhs.width), (short) (-rhs.height))); 
  670.     return *this;
  671. }
  672.  
  673. inline void TRect::CenterIn(const TRect& container)        
  674. {
  675.     this->MoveTo(container[topLeft] + (container.GetSize() - GetSize()) / 2);
  676. }
  677.  
  678. #pragma mark -
  679.  
  680. inline TLongPoint TLongPoint::operator+(const TLongSize& rhs) const    
  681. {
  682.     return TLongPoint(h + rhs.width, v + rhs.height);
  683. }
  684.  
  685. inline TLongPoint TLongPoint::operator-(const TLongSize& rhs) const    
  686. {
  687.     return TLongPoint(h - rhs.width, v - rhs.height);
  688. }
  689.  
  690. inline TLongPoint& TLongPoint::operator+=(const TLongPoint& rhs)    
  691. {
  692.     h += rhs.h; 
  693.     v += rhs.v; 
  694.     
  695.     return *this;
  696. }
  697.  
  698. inline TLongPoint& TLongPoint::operator-=(const TLongPoint& rhs)    
  699. {
  700.     h -= rhs.h; 
  701.     v -= rhs.v; 
  702.     
  703.     return *this;
  704. }
  705.  
  706. inline TLongPoint& TLongPoint::operator+=(const TLongSize& rhs)
  707. {
  708.     h += rhs.width; 
  709.     v += rhs.height; 
  710.     
  711.     return *this;
  712. }
  713.     
  714. inline TLongPoint& TLongPoint::operator-=(const TLongSize& rhs)
  715. {
  716.     h -= rhs.width; 
  717.     v -= rhs.height; 
  718.     
  719.     return *this;
  720. }
  721.  
  722. #pragma mark -
  723.  
  724. inline TLongSize& TLongSize::operator+=(const TLongSize& rhs)        
  725. {
  726.     width     += rhs.width; 
  727.     height     += rhs.height; 
  728.     return *this;
  729. }
  730.  
  731. inline TLongSize& TLongSize::operator-=(const TLongSize& rhs)    
  732. {
  733.     width     -= rhs.width; 
  734.     height     -= rhs.height; 
  735.     return *this;
  736. }
  737.  
  738. #pragma mark -
  739.  
  740.  
  741. inline TLongRect::TLongRect(const TLongPoint& topLeftPt, const TLongPoint& botRightPt)
  742. {
  743.     left    = topLeftPt.h;
  744.     top        = topLeftPt.v;
  745.     right    = botRightPt.h;
  746.     bottom    = botRightPt.v;
  747. }
  748.  
  749. inline TLongRect::TLongRect(const TLongPoint& topLeftPt, const TLongSize& size)
  750. {
  751.     left    = topLeftPt.h;
  752.     top        = topLeftPt.v;
  753.     right    = topLeftPt.h + size.width;
  754.     bottom    = topLeftPt.v + size.height;
  755. }
  756.  
  757. inline void TLongRect::Inset(long dx, long dy)
  758. {
  759.     top     += dy; 
  760.     left     += dx; 
  761.     bottom     -= dy; 
  762.     right     -= dx;
  763. }
  764.  
  765. inline void TLongRect::Inset(const TLongPoint& delta)                
  766. {
  767.     this->Inset(delta.h, delta.v);
  768. }
  769.  
  770. inline void TLongRect::MoveBy(const TLongPoint& rhs)
  771. {
  772.     left     += rhs.h; 
  773.     top     += rhs.v; 
  774.     right     += rhs.h; 
  775.     bottom     += rhs.v; 
  776. }
  777.  
  778. inline void TLongRect::MoveTo(const TLongPoint& pt)                
  779. {
  780.     this->MoveBy(TLongPoint(pt.h - left, pt.v - top));
  781. }
  782.  
  783. inline TLongRect& TLongRect::operator&=(const TLongRect& rhs)
  784. {
  785.     *this = *this & rhs; 
  786.     return *this;
  787. }
  788.     
  789. inline TLongRect& TLongRect::operator|=(const TLongRect& rhs)
  790. {
  791.     *this = *this | rhs; 
  792.     return *this;
  793. }
  794.  
  795. inline TLongRect& TLongRect::operator+=(const TLongPoint& rhs)
  796. {
  797.     this->MoveBy(rhs); 
  798.     return *this;
  799. }
  800.  
  801. inline TLongRect& TLongRect::operator-=(const TLongPoint& rhs)
  802. {
  803.     this->MoveBy(-rhs); 
  804.     return *this;
  805. }
  806.  
  807. inline TLongRect& TLongRect::operator+=(const TLongSize& rhs)
  808. {
  809.     this->MoveBy(TLongPoint(rhs.width, rhs.height)); 
  810.     return *this;
  811. }
  812.  
  813. inline TLongRect& TLongRect::operator-=(const TLongSize& rhs)
  814. {
  815.     this->MoveBy(TLongPoint(-rhs.width, -rhs.height)); 
  816.     return *this;
  817. }
  818.  
  819. inline void TLongRect::CenterIn(const TLongRect& container)        
  820. {
  821.     this->MoveTo(container[topLeft] + (container.GetSize() - GetSize()) / 2);
  822. }
  823.